<?php

use backend\components\helper\EasyHtml;
use mdm\admin\components\RouteRule;
use mdm\admin\components\Configs;
use backend\components\widget\adminLTE\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $searchModel mdm\admin\models\searchs\AuthItem */
/* @var $context mdm\admin\components\ItemController */

$context = $this->context;
$labels = $context->labels();
$this->title = Yii::t('rbac-admin', $labels['Items']);
$this->params['breadcrumbs'][] = $this->title;

$rules = array_keys(Configs::authManager()->getRules());
$rules = array_combine($rules, $rules);
unset($rules[RouteRule::RULE_NAME]);
?>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title"><?= EasyHtml::encode($this->title) ?></h3>
                <div class="box-tools pull-right">
                    <?= EasyHtml::iconLink('新增', ['create'], [
                        'icon' => 'plus',
                        'class' => 'btn btn-success layer-open',
                        'layer-title'  => Yii::t('rbac-admin', 'Create ' . $labels['Item']),
                        'layer-width'  => '50%',
                        'layer-height' => '50%',
                    ]) ?>
                </div>
            </div>
            <div class="box-tools form-inline">
                <?php echo $this->render('_search', ['model' => $searchModel]); ?>
                <div class="box-body">
                    <?= GridView::widget([
                        'dataProvider' => $dataProvider,
                        //'filterModel' => $searchModel,
                        'columns' => [
                            ['class' => 'yii\grid\SerialColumn'],
                            [
                                'attribute' => 'name',
                                'label' => Yii::t('rbac-admin', 'Name'),
                            ],
                            [
                                'attribute' => 'ruleName',
                                'label' => Yii::t('rbac-admin', 'Rule Name'),
                                'filter' => $rules
                            ],
                            [
                                'attribute' => 'description',
                                'label' => Yii::t('rbac-admin', 'Description'),
                            ],
                            [
                                'class' => 'backend\components\widget\adminLTE\ActionColumn',
                                'template' => '{view} {update} {delete}',
                                'buttons' => [
                                    'view' => function($url, $model, $key){
                                        return  EasyHtml::iconLink('分配路由', $url, [
                                            'icon' => 'list',
                                            'class' => 'btn btn-xs btn-primary layer-open',
                                            'layer-title'  => '分配路由-'.$model->name,
                                            'layer-width'  => '50%',
                                            'layer-height' => '78%',
                                        ]);
                                    },
                                    'update' => function($url, $model, $key){
                                        return  EasyHtml::iconLink('修改', $url, [
                                            'icon' => 'pencil',
                                            'class' => 'btn btn-xs btn-warning layer-open',
                                            'layer-title'  => '修改权限-'.$model->name,
                                            'layer-width'  => '50%',
                                            'layer-height' => '50%',
                                        ]);
                                    }
                                ],
                            ],
                        ],
                    ])
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>